package com.ruoyi.project.tickets.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.tickets.domain.SaleDetails;
import com.ruoyi.project.tickets.service.ISaleDetailsService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 销售详情Controller
 * 
 * @author 孙山伟
 * @date 2023-07-01
 */
@RestController
@RequestMapping("/tickets/saleDetails")
public class SaleDetailsController extends BaseController
{
    @Autowired
    private ISaleDetailsService saleDetailsService;

    /**
     * 查询销售详情列表
     */
    @PreAuthorize("@ss.hasPermi('tickets:saleDetails:list')")
    @GetMapping("/list")
    public TableDataInfo list(SaleDetails saleDetails)
    {
        startPage();
        List<SaleDetails> list = saleDetailsService.selectSaleDetailsList(saleDetails);
        return getDataTable(list);
    }

    /**
     * 导出销售详情列表
     */
    @PreAuthorize("@ss.hasPermi('tickets:saleDetails:export')")
    @Log(title = "销售详情", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SaleDetails saleDetails)
    {
        List<SaleDetails> list = saleDetailsService.selectSaleDetailsList(saleDetails);
        ExcelUtil<SaleDetails> util = new ExcelUtil<SaleDetails>(SaleDetails.class);
        return util.exportExcel(list, "saleDetails");
    }

    /**
     * 获取销售详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('tickets:saleDetails:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(saleDetailsService.selectSaleDetailsById(id));
    }

    /**
     * 新增销售详情
     */
    @PreAuthorize("@ss.hasPermi('tickets:saleDetails:add')")
    @Log(title = "销售详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SaleDetails saleDetails)
    {
        return toAjax(saleDetailsService.insertSaleDetails(saleDetails));
    }

    /**
     * 修改销售详情
     */
    @PreAuthorize("@ss.hasPermi('tickets:saleDetails:edit')")
    @Log(title = "销售详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SaleDetails saleDetails)
    {
        return toAjax(saleDetailsService.updateSaleDetails(saleDetails));
    }

    /**
     * 删除销售详情
     */
    @PreAuthorize("@ss.hasPermi('tickets:saleDetails:remove')")
    @Log(title = "销售详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(saleDetailsService.deleteSaleDetailsByIds(ids));
    }
}
